package com.ukao.steward.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.WaitingOrderBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.util.ActivityUtils;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.widget.StateButton;

import java.util.List;

import static com.ukao.steward.R.id.takePhone_layout;


public class UnpaidLetterAdapter extends ListBaseAdapter<WaitingOrderBean.ListBean> {


    public UnpaidLetterAdapter(Context context, List<WaitingOrderBean.ListBean> mDataList) {
        super(context, mDataList);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapte_unpaid_letterr;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, final int position) {
        TextView business=holder.getView(R.id.business);
        TextView orderNo=holder.getView(R.id.orderNo);
        TextView transNo=holder.getView(R.id.transNo);
        TextView takeName=holder.getView(R.id.takeName);
        TextView takePhone=holder.getView(R.id.takePhone);

        RelativeLayout pricesBtnLayout=holder.getView(R.id.prices_btn_layout);
        TextView userRemark=holder.getView(R.id.userRemark);
        TextView modifyPrice=holder.getView(R.id.modifyPrice);
        TextView payablePrice=holder.getView(R.id.payablePrice);
        TextView payStatusText=holder.getView(R.id.payStatusText);
        LinearLayout modifyPriceLayout=holder.getView(R.id.modifyPrice_layout);
        LinearLayout payablePriceLayout=holder.getView(R.id.payablePrice_layout);
        StateButton priceBtn=holder.getView(R.id.price_btn);
        LinearLayout takePhoneLayout=holder.getView(R.id.takePhone_layout);

        WaitingOrderBean.ListBean item = mDataList.get(position);
        transNo.setText(item.getTransNo());
        payStatusText.setText(item.getPayStatusText());
        orderNo.setText(item.getOrderNo());
        takePhone.setText(item.getTakePhone());
        takeName.setText(item.getTakeName());
      //  pricesBtnLayout.setVisibility(item.getPayStatus() ?View.GONE : View.VISIBLE);
        modifyPrice.setTextColor(item.getPayStatus() ? getColors(R.color.green) : getColors(R.color.red));
        payablePrice.setTextColor(item.getPayStatus() ? getColors(R.color.green) : getColors(R.color.red));
        payStatusText.setTextColor(item.getPayStatus() ? getColors(R.color.green) : getColors(R.color.red));
        userRemark.setText(item.getUserRemark());
        if (!CheckUtils.isEmpty(item.getBusiness())){
            business.setText(Constant.getbusiness(item.getBusiness()));
        }else{
            business.setText("");
        }
        if(CheckUtils.isNull(item.getPayablePrice())){
            payablePriceLayout.setVisibility(View.GONE);
        }else{
            payablePrice.setText(CheckUtils.isEmptyNumber(item.getPayablePrice()));
            payablePriceLayout.setVisibility(View.VISIBLE);
        }

        if(CheckUtils.isNull(item.getModifyPrice())){
            modifyPriceLayout.setVisibility(View.GONE);
        }else{
            modifyPrice.setText(CheckUtils.isEmptyNumber(item.getModifyPrice()));
            modifyPriceLayout.setVisibility(View.VISIBLE);
        }
        View.OnClickListener  OnClickListener= new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WaitingOrderBean.ListBean item = mDataList.get(position);
                if (v.getId()== takePhone_layout) {
                    if (!CheckUtils.isEmpty(item.getTakePhone())) {
                        ActivityUtils.callActivity(mContext, item.getTakePhone());
                    }
                    return;
                }

                if (mOnItemChildClickListener!=null){
                    mOnItemChildClickListener.onChildItemClick(v.getId(), position,item);
                }

            }
        };
        priceBtn.setOnClickListener(OnClickListener);
       // takePhoneLayout.setOnClickListener(OnClickListener);
    }


}
